package com.yidu.BusinessParament.controller;

import com.yidu.BusinessParament.entity.DealSeat;
import com.yidu.BusinessParament.service.DealSeatService;
import com.yidu.BusinessParament.util.IdUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @交易席位 Controller类
 * @version 1.0
 * @auther 林肯
 * @date 2022/12/12 -9:50
 */
@RestController
public class DealSeatController {
    @Resource
    private DealSeatService dealSeatService;

    /**
     * 查询数据
     * @param page 页码
     * @param limit 每页显示的条数
     * @param dealSeat 交易席位
     * @return
     */
    @RequestMapping("/selectDealSeat")
    public Map selectDealSeat(int page, int limit, DealSeat dealSeat){
        //查询加分页
        List<DealSeat> dealSeatList = dealSeatService.selectDealSeat(page,limit,dealSeat);
        //查行数
        int count = dealSeatService.selectCount(dealSeat);
        System.out.println("行数"+count);
        //创建Map对象
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",dealSeatList);
        //返回值
        return map;
    }

    /**
     * 添加数据
     * @param dealSeat 交易数据
     * @return
     */
    @RequestMapping("/insertDealSeat")
    public int insertDealSeat(DealSeat dealSeat){
        System.out.println("进来了新增的方法!");
        //得到最大的ID
        String maxId = dealSeatService.selectMaxId();
        //得到工具类
        IdUtil idUtil=new IdUtil();
        //得到工具类id的方法
        String id = idUtil.createID(maxId);
        System.out.println("新ID为"+id);//设置券商ID
        dealSeat.setSeatId(id);
        //调用券商新增的方法
        int i = dealSeatService.insertDealSeat(dealSeat);
        //返回值
        return i;
    }

    /**
     * 删除数据
     * @param seatId 交易席位
     * @return
     */
    @RequestMapping("/deleteDealSeat")
    public int deleteDealSeat(String seatId){
        System.out.println("进来了删除方法!"+seatId);
        int i = dealSeatService.deleteDealSeat(seatId);
        if (i>0){
            System.out.println("删除成功!");
        } else {
            System.out.println("删除失败!");
        }
        return i;
    }

    /**
     * 修改数据
     * @param dealSeat 交易席位
     * @return
     */
    @RequestMapping("/updateDealSeat")
    public int updateDealSeat(DealSeat dealSeat){
        System.out.println("进来了修改方法!"+dealSeat);
        int i = dealSeatService.updateDealSeat(dealSeat);
        if (i>0){
            System.out.println("修改成功!");
        } else {
            System.out.println("修改失败!");
        }
        return i;
    }
}
